clear 
ssc install kict 				// installs kict command to test no design effect assumption  
quietly cd "your working directory" 	// sets your working directory (save dataset and dofile there)
quietly log using "UDADHF_replication", replace	// Log file 
use "UDADHF_replication.dta" 	// loads dataset 


/* 
AUTHOR:		Ursula Daxecker, Annekatrin Deglow and Hanne Fjelde	   
ARTICLE:	Voter Intimidation as a Tool of Mobilization or Demobilization? Evidence from West Bengal, India
JOURNAL:  	Jounal of Conflict Resolution
*/

*-------------------------------------------------------------------------------
* TABLE 1 (HYPOTHESES 1)
*-------------------------------------------------------------------------------
* Proportiom of violent threat (pooled, mobilization, demobilization), list experiment
foreach var of varlist control_treat control_mob control_demob { // loops over type of threat and produces...
	
ttest list_activities, by(`var') unequal // Proportion of threat for pooled, mobilization, and demobilization
gen diff_`var'= abs((r(mu_1)- r(mu_2)))  // Difference in item counts = proportion of respondent estimated to be threatened (pooled/mobilized/demobilized)
gen n_`var' = r(N_1)+r(N_2)              // Total N for comparisons

}

/* Statistical significance for difference between the estimated proportion of mobilization and demobilization threats 
--> calculate confidence (CI) intervals for the difference in proportion; if CI does not include 0 = statistically significant difference */
di (diff_control_demob - diff_control_mob) // Difference 
di (diff_control_demob - diff_control_mob) - 1.96*sqrt((diff_control_demob*(1-diff_control_demob)/n_control_demob)+(diff_control_mob*(1-diff_control_mob)/n_control_mob)) // 95 CI lower bound
di (diff_control_demob - diff_control_mob) + 1.96*sqrt((diff_control_demob*(1-diff_control_demob)/n_control_demob)+(diff_control_mob*(1-diff_control_mob)/n_control_mob)) // 95 CI upper bound
di (diff_control_demob - diff_control_mob) - 2.58*sqrt((diff_control_demob*(1-diff_control_demob)/n_control_demob)+(diff_control_mob*(1-diff_control_mob)/n_control_mob)) // 99 CI lower bound


*-------------------------------------------------------------------------------
* TABLE 2 (HYPOHTESES 2 & 3; PARLIAMENTARY CONSTITUENCY)
*-------------------------------------------------------------------------------
* Proportion of mobilization threats by electoral geography, list experiment
foreach var of varlist contested bjp_strong tmc_strong {

ttest list_activities if `var'==1, by(control_mob) unequal 	  
gen diff_mob_`var' = abs((r(mu_1) - r(mu_2)))                 
gen n_mob_`var' = r(N_1)+r(N_2)                               
}


* Proportion of demobilization threats by electoral geography, list experiment 
foreach var of varlist contested bjp_strong tmc_strong {     
	   
ttest list_activities if `var'==1, by(control_demob) unequal 	
gen diff_demob_`var' = abs((r(mu_1) - r(mu_2)))                
gen n_demob_`var' = r(N_1)+r(N_2)      
                         
}

* Difference in proportion of mobilization and demobilization threats by electoral geography (statistical significance based on CIs not including 0), list experiment
local pairs "contested bjp_strong contested tmc_strong bjp_strong tmc_strong"
local vars "mob demob"

foreach var in `vars' {
	
    forvalues i = 1(2)5 {
        * Extract group names for each pair
        local g1 : word `i' of `pairs'
        local g2 : word `=`i'+1' of `pairs'

        * Calculate and display difference in proportions
        di abs(diff_`var'_`g1' - diff_`var'_`g2') ///
            " // Difference in `var' between `g1' and `g2'"
        
        * Calculate standard error for difference in proportions
        local se = sqrt((diff_`var'_`g1'*(1-diff_`var'_`g1')/n_`var'_`g1') + ///
                        (diff_`var'_`g2'*(1-diff_`var'_`g2')/n_`var'_`g2'))
        di `se' " // Standard error for difference"

		* Calculate and display 90%, 95% and 99% CI for difference in proportions
        di abs(diff_`var'_`g1' - diff_`var'_`g2') - 1.645*`se' ///
            " // 90% CI lower bound"
        di abs(diff_`var'_`g1' - diff_`var'_`g2') + 1.645*`se' ///
            " // 90% CI upper bound"
        di abs(diff_`var'_`g1' - diff_`var'_`g2') - 1.96*`se' ///
            " // 95% CI lower bound"
        di abs(diff_`var'_`g1' - diff_`var'_`g2') + 1.96*`se' ///
            " // 95% CI upper bound"
        di abs(diff_`var'_`g1' - diff_`var'_`g2') - 2.58*`se' ///
            " // 99% CI lower bound"
        di abs(diff_`var'_`g1' - diff_`var'_`g2') + 2.58*`se' ///
            " // 99% CI upper bound"
    }
}

*-------------------------------------------------------------------------------
* TABLE 2 (HYPOTHESES 2 & 3; 5 CLOSEST POLLING STATIONS)
*-------------------------------------------------------------------------------
* Proportion of mobilization threats by electoral geography, list experiment 
foreach var of varlist contested_ps bjp_strong_dummy_ps tmc_strong_dummy_ps { 

ttest list_activities if `var'==1, by(control_mob) unequal 	   
gen diff_mob_`var' = abs((r(mu_1) - r(mu_2)))                 
gen n_mob_`var' = r(N_1)+r(N_2)                               
}


* Proportion of demobilization threats by electoral geography, list experiment
foreach var of varlist contested_ps bjp_strong_dummy_ps tmc_strong_dummy_ps  {        

ttest list_activities if `var'==1, by(control_demob) unequal 	
gen diff_demob_`var' = abs((r(mu_1) - r(mu_2)))                
gen n_demob_`var' = r(N_1)+r(N_2)                               
}


* Difference in proportions of mobilization and demobilization threats by electoral geography, list experiment
local pairs "contested_ps bjp_strong_dummy_ps contested_ps tmc_strong_dummy_ps bjp_strong_dummy_ps tmc_strong_dummy_ps"
local vars "mob demob"

foreach var in `vars' {
    forvalues i = 1(2)5 {
        * Extract group names for each pair
        local g1 : word `i' of `pairs'
        local g2 : word `=`i'+1' of `pairs'

        * Calculate and display difference in proportions
        di abs(diff_`var'_`g1' - diff_`var'_`g2') ///
            " // Difference in `var' between `g1' and `g2'"
        
        * Calculate standard error for difference in proportions
        local se = sqrt((diff_`var'_`g1'*(1-diff_`var'_`g1')/n_`var'_`g1') + ///
                        (diff_`var'_`g2'*(1-diff_`var'_`g2')/n_`var'_`g2'))
        di `se' " // Standard error for difference"

		* Calculate and display 90%, 95% and 99% CI for difference in proportions
        di abs(diff_`var'_`g1' - diff_`var'_`g2') - 1.645*`se' ///
            " // 90% CI lower bound"
        di abs(diff_`var'_`g1' - diff_`var'_`g2') + 1.645*`se' ///
            " // 90% CI upper bound"
        di abs(diff_`var'_`g1' - diff_`var'_`g2') - 1.96*`se' ///
            " // 95% CI lower bound"
        di abs(diff_`var'_`g1' - diff_`var'_`g2') + 1.96*`se' ///
            " // 95% CI upper bound"
        di abs(diff_`var'_`g1' - diff_`var'_`g2') - 2.58*`se' ///
            " // 99% CI lower bound"
        di abs(diff_`var'_`g1' - diff_`var'_`g2') + 2.58*`se' ///
            " // 99% CI upper bound"
    }
}

*-------------------------------------------------------------------------------
* Table 3 (observable implications; same as Table A.3 in the appendix)
*-------------------------------------------------------------------------------
local outcomes "mob dem" 
local voter_status "0 1"


* (1) Comparison direct question vs. list experiment for mobilization and demobilization (sample average)
foreach outcome in `outcomes' {
	
    // Mobilization and demobilization estimates based on direct questions
    reg vio_`outcome' if treatment != cond("`outcome'" == "mob", 2, 1)

    // Store the estimate and sample size
    gen direct_`outcome' = _b[_cons]
    gen n_direct_`outcome' = e(N)

    // Calculate and display the difference between list experiment and direct question
    di "Difference between list experiment and direct question for `outcome':"
    di (diff_control_`outcome' - direct_`outcome')

    // Calculate and display the standard error for the difference
    local se_diff = sqrt((diff_control_`outcome'*(1-diff_control_`outcome')/n_control_`outcome') + (direct_`outcome'*(1-direct_`outcome')/n_direct_`outcome'))
    di "Standard error for the difference: " `se_diff'

	// Calculate and display the 90%, 95% and 99% CI for the difference
    di "90% Confidence interval for the difference:"
    di (diff_control_`outcome' - direct_`outcome') - 1.645*`se_diff'
    di (diff_control_`outcome' - direct_`outcome') + 1.645*`se_diff'
    di "95% Confidence interval for the difference:"
    di (diff_control_`outcome' - direct_`outcome') - 1.96*`se_diff'
    di (diff_control_`outcome' - direct_`outcome') + 1.96*`se_diff'
    di "99% Confidence interval for the difference:"
    di (diff_control_`outcome' - direct_`outcome') - 2.58*`se_diff'
    di (diff_control_`outcome' - direct_`outcome') + 2.58*`se_diff'   
}


* (2) Comparison direct question vs. list experiment for mobilization and demobilization, by voter status 
// (2.1) Mobilization and demobilization estimates based on list experiment by vote status
foreach condition in mob demob {
    foreach vote_status in 0 1 {
        
        * Proportion of mobilization and demobilization threats, by vote status
        ttest list_activities if voted==`vote_status', by(control_`condition') unequal
        
        * Difference in means and total sample size for mobilization and demobilization by vote status
        gen diff_control_`condition'_vote`vote_status' = abs(r(mu_1) - r(mu_2)) 
        gen n_control_`condition'_vote`vote_status' = r(N_1) + r(N_2)
    }
}


// (2.2) Mobilization and demobilization estimates based on direct question, by vote status
foreach condition in mob demob {
    foreach vote_status in 0 1 {
        
		* Proportion of mobilization and demobilization
        if "`condition'" == "mob" {
            reg vio_mobilize if voted==`vote_status' & treatment !=2
        }
        else if "`condition'" == "demob" {
            reg vio_demobilize if voted==`vote_status' & treatment !=1
        }

        * Save direct estimates and sample sizes
        gen direct_`condition'_vote`vote_status' = _b[_cons]
        gen n_direct_`condition'_vote`vote_status' = e(N)
    }
}


// (2.3) Difference between list experiment and direct estimate for mobilization and demobilization, by vote status
foreach condition in mob demob {
    foreach vote_status in 0 1 {
        
        local diff_control_var = "diff_control_`condition'_vote`vote_status'"
        local direct_var = "direct_`condition'_vote`vote_status'"
        local n_control_var = "n_control_`condition'_vote`vote_status'"
        local n_direct_var = "n_direct_`condition'_vote`vote_status'"
        
        // Calculate and display the difference between LE and direct estimates
        di "Difference between LE and direct estimate for `condition' (voted == `vote_status'): " ///
           (`=`diff_control_var'' - `=`direct_var'')
        
        // Calculate and display the standard error of the difference
        di "Standard error of the difference for `condition' (voted == `vote_status'): " ///
           sqrt((`=`diff_control_var'' * (1 - `=`diff_control_var'') / `=`n_control_var'') + ///
                (`=`direct_var'' * (1 - `=`direct_var'') / `=`n_direct_var''))
        
        // Calculate and display the lower and upper bound of the 95% CI
        di "95% CI lower bound for the difference for `condition' (voted == `vote_status'): " ///
           (`=`diff_control_var'' - `=`direct_var'') - 1.96 * ///
           sqrt((`=`diff_control_var'' * (1 - `=`diff_control_var'') / `=`n_control_var'') + ///
                (`=`direct_var'' * (1 - `=`direct_var'') / `=`n_direct_var''))
        di "95% CI upper bound for the difference for `condition' (voted == `vote_status'): " ///
           (`=`diff_control_var'' - `=`direct_var'') + 1.96 * ///
           sqrt((`=`diff_control_var'' * (1 - `=`diff_control_var'') / `=`n_control_var'') + ///
                (`=`direct_var'' * (1 - `=`direct_var'') / `=`n_direct_var''))
		// Calculate and display the lower and upper bound of the 99% CI
        di "99% CI lower bound for the difference for `condition' (voted == `vote_status'): " ///
           (`=`diff_control_var'' - `=`direct_var'') - 2.58 * ///
           sqrt((`=`diff_control_var'' * (1 - `=`diff_control_var'') / `=`n_control_var'') + ///
                (`=`direct_var'' * (1 - `=`direct_var'') / `=`n_direct_var''))
        di "99% CI lower bound for the difference for `condition' (voted == `vote_status'): " ///
           (`=`diff_control_var'' - `=`direct_var'') + 2.58 * ///
           sqrt((`=`diff_control_var'' * (1 - `=`diff_control_var'') / `=`n_control_var'') + ///
                (`=`direct_var'' * (1 - `=`direct_var'') / `=`n_direct_var''))
				
    }
}

*-------------------------------------------------------------------------------
* Appendix
*-------------------------------------------------------------------------------
/* C. Test of assumptions: Balance test (Table A.1)
Regress treatment assignment on key demographics */ 
mlogit 	treatment age women urban i.caste i.rel i.edu upperclass middleclass lowerclass, baseoutcome(0)


* C. Test of assumptions: No design effects (Table A.2)
kict deff list_activities, nnonkey(4) condition(control_mob)   
kict deff list_activities, nnonkey(4) condition(control_demob) 


* D. Analysis of item non-responses (Figure A.1)
foreach var of varlist dkr_listexp dk_listexp r_listexp {
logit `var' i.treatment 
est store M_`var'
}
 
coefplot 	(M_dk_listexp, xline(0, lcolor(red%60) lpattern(dash)) drop(_cons) label(Don't know) ///
            legend(cols(1) region(lstyle(none))) xscale(range(-0.75,0.25,0.75)) xlabel(-0.75(0.25)0.75) )  ///
			(M_r_listexp, drop(_cons)label(Refused)) ///
			(M_dkr_listexp,drop(_cons) label(Don't know + refused)) 

			
/* F. Probing observable implications (Table A.3)
See code for Table 3 above */



***
quietly log close // end log file 
translate UDADHF_replication.smcl UDADHF_replication.pdf, replace // saves log file as pdf 




